package web;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Map;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import bus.User;
import bus.UserManager;

public class WebcalendarController implements Controller {
    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());
    
    private UserManager userManager;
    
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    	
    	String now = (new java.util.Date().toString());
    	logger.info("returning login view with " + now);
    	
    	Map myModel = new HashMap();
    	myModel.put("now", now);
    	myModel.put("users", getUserManager().getUsers());
    	
        return new ModelAndView("login", "model", myModel);
    }
    
    public void setUserManager(UserManager pm) {
    	userManager = pm;
    }
    
    public UserManager getUserManager() {
    	return userManager;
    }
}
